home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / MARKMAIL.SLT < prev    next >
Text File  |  1992-03-20  |  13KB  |  384 lines

  1. //-----------------------------------------------------------
  2. // MarkMail.SL?   Telix script to fetch mail from a PCBoard BBS.
  3. //
  4. // This script is normally called from the script PCBOARD.SLC.
  5. //
  6. // Please look at the comments through the whole file, and modify to
  7. // suit your needs, BEFORE you use it. Then recompile with CS MarkMail.
  8. //-----------------------------------------------------------
  9.  
  10. // This script is assumed to be called ONLY after logon
  11. // to perform routine tasks. This is done from the LOGON
  12. // script, and the system can ONLY be PCBOARD. Also,
  13. // we MUST be online in order to arrive here, and the
  14. // TELIX main directory must be the current one.
  15. // Therefore, system and online checks are simply skipped.
  16.  
  17. // If you have suggestions for improving this script, please suggest
  18. // improvements to me via old-fashioned snail-mail to:
  19.  
  20. // Author:  Inge Vabekk
  21. //          Hamangskogen 108
  22. //          N-1300 SANDVIKA
  23. //          NORWAY
  24. //          tel. (472) 546 396
  25.  
  26. str codename [12]            // BBS code/filename
  27.    ,myprot    [2]            // My protocol name
  28.    ,hisprot   [2]            // Board's protocol name
  29.    ,help     [80]            // Help line.
  30.    ,runstr   [80]            // DSZ runstring (if used).
  31.                              // Script and global names:
  32.    ,global     []="GLOBAL"   // Global script.
  33.    ,PutLine    []="PUTLINE"  // PutLine script.
  34.    ,Cprot      []="CPROT"    // Current protocol.
  35.    ,Hprot      []="HPROT"    // Board's protocol name.
  36.    ,Cname      []="CNAME"    // Codename of current BBS.
  37.    ,prompt     []="PROMPT"   // Current command prompt.
  38.    ,mdir       []="MDIR"     // Mail directory.
  39.    ,dsz        []="DSZ"      // Code for DSZ (if in use).
  40.    ;     
  41.  
  42. int tol = 300                // No activity for 30 sec.
  43.    ,tmark                    // makes script time out. 
  44.    ,stat                     // For tracking.
  45.    ,Enter = 13               // Enter (CR)
  46.    ;                           
  47.  
  48. //-----------------------------------------------------------
  49. // MarkMail script is entered here.                                   
  50. //-----------------------------------------------------------
  51.  
  52. main()
  53. {
  54. int c
  55.    ,i
  56.    ,l
  57.    ,na
  58.    ,save
  59.    ,error                              // Error ind.      
  60.    ,Mail  
  61.    ,com                                // command
  62.    ,pnm                                // Packet name
  63.    ,stf                                // Start transfer
  64.    ,don                                // [G]oodbye When Done?
  65.    ,pro                                // Signal to enter protocol.
  66.    ;
  67.  
  68.   pnm = 0;
  69.   if (read(cname,Codename) < 0)        // If codename is unknown,
  70.     pnm = track ("ket Name: ",0);      // Get packet name.
  71.   stf = track ("s Transfer",0);        // Start tracking this now.
  72.   pro = track ("er)=abort?",0);        // Enter protocol.
  73.  
  74.   entry();                             // Update status bar.
  75.   newdir (_telix_dir);                 // Must be in TELIX main directory!
  76.   read (cprot,myprot);                 // Get current BBS protocol.
  77.  
  78.   read (hprot,hisprot);                // Get board's protocol name.
  79.  
  80.   tmark = timer_start (tol);           // Give me a minute.
  81.   call (PutLine,"U", Enter);           // Send Upload command.
  82.  
  83.   while ((stat=trig()) > 0)            // answer any questions.
  84.   { if (stat == pro)                   // Enter protocol?
  85.       call (PutLine,hisprot, Enter);
  86.  
  87.     else if (stat == pnm)              // Packet name?
  88.     { waitfor ("^J",1);                // Wait for linefeed.
  89.       for (l=gety(); l>=0; --l)        // Find "Packet name" line.
  90.       { vgetchrs(0,l,help,0,80);
  91.         if ((i=strposi (help,"ket Name: ",0)) > 0) // Packet name?
  92.         { i = i+9;
  93.           na = 0;
  94.           while ((c=subchr(help,++i)) != '.') // All before decimal point:
  95.           { setchr(codename,na,c);
  96.             if (++na > 11) break;
  97.           }
  98.           setchr (codename,na,0);      // End the string.
  99.           write (cname,codename);      // Save BBS ID-code.
  100.           break;                       // Break out of (inner) loop.
  101.         }
  102.       }
  103.     }
  104.     else if (stat==stf)                // Start transfer
  105.       break;
  106.   }
  107.   release();                           // Release tracks.
  108.   if (stat < 0) goto done;             // Time-out or carrier lost.
  109.  
  110. // Start sending the mail packet.
  111.  
  112.   help = _up_dir;                      // Get upload dir.
  113.   i = strlen(help)-1;
  114.   if (subchr(help,i)!='\')             // Append "\" if  
  115.     strcat (help,"\");                 // necessary.
  116.   strcat (help,codename);              // Add name.
  117.   strcat (help,".REP");                // Add extension.
  118.   prints ("");
  119.   printsc ("T²: Upload mail file: ");
  120.   prints (help);
  121.  
  122.   if (filesize(help) <= 0)             // No file to send?
  123.     goto abort;                        // Abort transfer.
  124.   else
  125.   { send_file ();                      // Send it.
  126.     fdelete (help);                    // Remove the mail file.
  127.   }
  128.  
  129. // Start download.
  130. // Define strings for tracking.
  131. //-----------------------------------------------------------
  132.  
  133.   com = track (" Command?",0);         // Back to command.
  134.   stf = track ("s Transfer",0);        // Start transfer.
  135.   pnm = track ("No Message",0);        // No messages.
  136.   don = track ("When Done?",0);        // Wanna receive?
  137.   pro = track ("er)=abort?",0);        // Enter protocol.
  138.  
  139.   Mail = 0;
  140.   tmark = timer_start (tol);           // Give me a minute.
  141.  
  142.   error = 1;                           // Set to 0 when done.
  143.   while ((stat=trig()) > 0)            // Answer any questions.
  144.   { if (stat == pro)                   // Enter protocol?
  145.       call (PutLine,hisprot, Enter);
  146.  
  147.     else if (stat == stf)              // Download now?
  148.       error = get_file();
  149.  
  150.     else if (stat==pnm)
  151.       error = 0;                       // No messages. Simulate "done".
  152.  
  153.     else if (stat==don)                // Wanna receive now?
  154.       call (PutLine,"Y", Enter);
  155.  
  156.     else if (stat==com)
  157.     { if (Mail) break;                 // No mail?
  158.       call (PutLine,"D", Enter);       // So download now.
  159.       Mail = 1;
  160.     }
  161.   }
  162.   error = 0;
  163.   goto done;
  164. abort:
  165.   release();                           // Free all tracks and timer.
  166.   MarkAbort();
  167.   error = 1;
  168. done:
  169.   release();                           // Free all tracks and timer.
  170.   if (error) 
  171.     failtone();
  172.   else
  173.     goodtone();
  174.  
  175.   call (PutLine,"Q", Enter);           // Quit MarkMail.
  176.   return (error);
  177. }
  178.  
  179. //-----------------------------------------------------------
  180. // Routine to update colors and status bar.
  181. //-----------------------------------------------------------
  182.  
  183. entry ()
  184. {
  185.   _back_color = 1;
  186.   _fore_color = 14;
  187.   update_term();
  188. }
  189.  
  190. //-----------------------------------------------------------
  191. // Play fail tone.
  192. //-----------------------------------------------------------
  193.  
  194. failtone()
  195. {
  196.   int n;
  197.   for (n=140; n > 10; n = 100*n/120) 
  198.   { tone(n*10,12);                     // Fail tone!!
  199.     terminal();                        // Process text.
  200.   }
  201. }
  202.  
  203. //-----------------------------------------------------------
  204. // Play good tune.
  205. //-----------------------------------------------------------
  206.  
  207. goodtone()
  208. {
  209. int n;
  210.   for (n=20; n < 200; n = 144*n/100) 
  211.   { tone(n*10,6);                      // Good tone!
  212.     terminal();                        // Process text.
  213.   }
  214. }
  215.  
  216. //-----------------------------------------------------------
  217. // Free timer and tracking functions.
  218. //-----------------------------------------------------------
  219.  
  220. release()
  221. {
  222.   timer_free (tmark);                  // free timer channel
  223.   track_free (0);                      // and all track channels.
  224. }
  225.  
  226. //-----------------------------------------------------------
  227. //  Trig loop. Waits here until either one "trig string" is
  228. //  found, or we have a time-out, or carrier is lost.
  229. //-----------------------------------------------------------
  230.  
  231. trig()
  232. {
  233. int i;
  234.   do
  235.   { terminal();
  236.     i = 0;
  237.     if (!carrier()) break;
  238.   }  while (!time_up (tmark)           // Loop until time-out
  239.